import request from "@/utils/request";
import type { BaseSaleAttrListModel, findBySpuModel, SpuImageListModel, spuModel, spuPageListModel, SpuSaleAttrListModel } from "./model/spuModel";

enum API {
  // 获取列表 GET /admin/product/{page}/{limit}
  getSpuList = "admin/product",

  // 更新 POST /admin/product/updateSpuInfo
  updateSpuInfo = "admin/product/updateSpuInfo",

  // 添加 POST /admin/product/saveSpuInfo
  saveSpuInfo = "/admin/product/saveSpuInfo",

  // 删除 DELETE /admin/product/deleteSpu/{spuId}
  deleteSpu = "/admin/product/deleteSpu",

  // SKU列表 GET /admin/product/findBySpuId/{spuId}
  FindBySpu = "/admin/product/findBySpuId",

  GetBaseSaleAttrList = '/admin/product/baseSaleAttrList',

  GetSpuSaleAttrList = '/admin/product/spuSaleAttrList',
  GetSpuImageList = '/admin/product/spuImageList',
  GetSpuInfo = '/admin/product/getSpuById',
}


// 获取spu分页列表
export const getSpuListApi = (page: number, limit: number, category3Id: number) => {
  return request.get<any, spuPageListModel>(API.getSpuList + `/${page}/${limit}?category3Id=${category3Id}`);
};

// 获取spu的详情 sku
export const FindBySpuApi = (spuId: number) => {
  return request.get<any, findBySpuModel[]>(API.FindBySpu + `/${spuId}`);
};



// 添加或者修改
export const addOrUpdateSpuApi = (spu: spuModel) => {
  return request.post(spu.id ? API.updateSpuInfo : API.saveSpuInfo, spu);
};

/**
 * 获取基础销售属性列表
 * @returns BaseSaleAttrListModel
 */
export const getBaseSaleAttrListApi = () => {
  return request.get<any, BaseSaleAttrListModel>(API.GetBaseSaleAttrList);
};

/**
 * 获取图片列表
 * @param spuId
 * @returns SpuImageListModel  SPU图片列表
 */
export const getSpuImageListApi = (spuId: number) => {
  return request.get<any, SpuImageListModel>(API.GetSpuImageList + `/${spuId}`);
};


/**
 * 获取销售属性列表
 * @param spuId
 * @returns SpuSaleAttrListModel  Spu销售属性值列表
 */
export const getSpuSaleAttrListApi = (spuId: number) => {
  return request.get<any, SpuSaleAttrListModel>(API.GetSpuSaleAttrList + `/${spuId}`);
};

/**
 * 获取SPU详情
 * @param spuId
 * @returns SpuModel  spu详情信息
 */
export const getSpuInfoApi = (spuId: number) => {
  return request.get<any, spuModel>(API.GetSpuInfo + `/${spuId}`);
};